package IC.Symbols;

import IC.SemanticError;
import IC.AST.ICClass;
import IC.Types.ClassType;
import IC.Types.TypeTable;

public class GlobalSymbolTable extends SymbolTable {

	public GlobalSymbolTable(String id) {
		super(id);
	}
	
	public void insert(ICClass icClass) throws SemanticError{
		String name = icClass.getName();
		ClassType classType = TypeTable.classType(name, icClass.getSuperClassName(), icClass);
		ClassSymbol symbol = new ClassSymbol(icClass.getName(), Kind.CLASS, classType, icClass.getOrder());
		Symbol previous = entries.put(name, symbol);
		if (previous != null){
			throw new SemanticError(icClass.getLine(), "a class with name " + name + " is already defined");
		}
	}
	
	public String getDisplayString(){
		return "Global Symbol Table: " + name;
	}
}